package 题目集.并查集;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class 发现环 {
    static int[] parent;
    static int[] size;
    static int n;

    public static boolean union(int o1, int o2) {
        o1 = find(o1);
        o2 = find(o2);
        if (o1 == o2) { //存在环
            return false;
        }
        if (size[o1] > size[o2]) {
            parent[o2] = o1;
            size[o1] += size[o2];
        } else {
            parent[o1] = o2;
            size[o2] += size[o1];
        }
        return true;
    }

    public static int find(int x) {
        return parent[x] == x ? x : (parent[x] = find(parent[x]));
    }

    static int[] res;
    static int cnt;
    static int s, e;
    static List<Integer>[] graph;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        graph =new List[n+1];
        parent = new int[n + 1];
        size = new int[n + 1];
        for (int i = n; i > 0; i--) {
            graph[i] = new ArrayList<>();
            parent[i] = i;
            size[i] = 1;
        }
        for (int i = 0; i < n; i++) {
            int o1 = sc.nextInt();
            int o2 = sc.nextInt();
            if (!union(o1, o2)) {   //发现环
                res = new int[size[find(o1)]];
                s = o1;
                e = o2;
                dfs(-1,s);
                break;
            }
            graph[o1].add(o2);
            graph[o2].add(o1);
        }
        Arrays.sort(res,0,cnt);
        for (int i = 0; i < cnt; i++) {
            System.out.print(res[i]+" ");
        }
    }

    //打印所有父节点为x的节点
    public static boolean dfs(int from, int cur) {
        if (cur == e) {
            res[cnt++] = cur;
            return true;
        }
        for (Integer to : graph[cur]) {
            if (to == from) continue;
            if (dfs(cur, to)) {
                res[cnt++] = cur;
                return true;
            }
        }
        return false;
    }
}
